package com.core.system.reckerMQ.imMessage;

import com.core.system.dao.SystemUserMapper;
import com.pojo.entity.SystemUserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
@Slf4j
public class ImServerLogOut implements ImServer{

    private SystemUserMapper systemUserMapper;

    public ImServerLogOut(SystemUserMapper systemUserMapper){
        this.systemUserMapper = systemUserMapper;
    }

    @Override
    public void execute(ImServerInfo info) {
        String body = info.getBody();
        log.info("获取登出用户ID:{}", body);
        if (!Objects.isNull(body)) {
            SystemUserEntity user = systemUserMapper.selectById(Long.parseLong(body));
            try {
                systemUserMapper.updateOnLine(Long.parseLong(body));
                //执行删除token操作
                log.info("用户：{}登出成功", user.getNickName());
            } catch (Exception e) {
                e.printStackTrace();
                log.info("执行登出方法异常，异常信息:{}", e.getMessage());
            } finally {
                log.info("用户登出执行完毕");
            }
        }
    }
}
